package pl.gpms.server.persistance.map;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import pl.gpms.client.dto.EstimateDTO;

@Entity
@Table(name = "T_ESTIMATE")
public class Estimate implements Serializable {

	private static final long serialVersionUID = 1L;
	private long id;
	private Date estDate;
	private String result;
	private Objects estimateObject;
	
	public Estimate() {}
	public Estimate( Date estDate, String result, Objects objects ) {
		this.estDate = estDate;
		this.result = result;
		this.estimateObject = objects;
	}
	
	public Estimate( EstimateDTO estimate ) {
		SimpleDateFormat formatter = new SimpleDateFormat("d/M/yyyy");
		
		this.id = estimate.getId();
		this.result = estimate.getResult();
		try {
			this.estDate = formatter.parse(estimate.getEstDate());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Id
	@GeneratedValue( strategy = GenerationType.IDENTITY )
	@Column( name="EST_ID", unique = true, nullable = false )
	public long getId() {
		return this.id;
	}
	
	public void setId( long id ) {
		this.id = id;
	}
	
	@Column( name="EST_DATE", unique = false, nullable = false )
	public Date getEstDate() {
		return estDate;
	}
	
	public void setEstDate( Date estDate ) {
		this.estDate = estDate;
	}
	
	@Column( name="EST_RESULT", unique = false, nullable = true )
	public String getResult() {
		return result;
	}
	
	public void setResult( String result ) {
		this.result = result;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="EST_OBJ_ID")
	public Objects getEstimateObject() {
		return estimateObject;
	}
	
	public void setEstimateObject(Objects object) {
		this.estimateObject = object;
	}
}
